char *key;
char *uri;
gboolean thumbnail;
+ gboolean enforced_square;
char *mimetype;
GtkRecentInfo *recent_info;
char *checksum;
} AsyncTextureLoadData;
static CoglHandle
-pixbuf_to_cogl_handle (GdkPixbuf *pixbuf)
-{
- return cogl_texture_new_from_data (gdk_pixbuf_get_width (pixbuf),
- gdk_pixbuf_get_height (pixbuf),
- COGL_TEXTURE_NONE,
- gdk_pixbuf_get_has_alpha (pixbuf) ? COGL_PIXEL_FORMAT_RGBA_8888 : COGL_PIXEL_FORMAT_RGB_888,
- COGL_PIXEL_FORMAT_ANY,
- gdk_pixbuf_get_rowstride (pixbuf),
- gdk_pixbuf_get_pixels (pixbuf));
+pixbuf_to_cogl_handle (GdkPixbuf *pixbuf,
+ gboolean add_padding)
+{
+ CoglHandle texture, offscreen;
+ CoglColor clear_color;
+ int width, height;
+ guint size;
+
+ width = gdk_pixbuf_get_width (pixbuf);
+ height = gdk_pixbuf_get_height (pixbuf);
+ size = MAX (width, height);
+
+ if (!add_padding || width == height)
+ return cogl_texture_new_from_data (width,
+ height,
+ COGL_TEXTURE_NONE,
+ gdk_pixbuf_get_has_alpha (pixbuf) ? COGL_PIXEL_FORMAT_RGBA_8888 : COGL_PIXEL_FORMAT_RGB_888,
+ COGL_PIXEL_FORMAT_ANY,
+ gdk_pixbuf_get_rowstride (pixbuf),
+ gdk_pixbuf_get_pixels (pixbuf));
+
+ texture = cogl_texture_new_with_size (size, size,
+ COGL_TEXTURE_NO_SLICING,
+ COGL_PIXEL_FORMAT_ANY);
+
+ offscreen = cogl_offscreen_new_to_texture (texture);
+ cogl_color_set_from_4ub (&clear_color, 0, 0, 0, 0);
+ cogl_push_framebuffer (offscreen);
+ cogl_clear (&clear_color, COGL_BUFFER_BIT_COLOR);
+ cogl_pop_framebuffer ();
+ cogl_handle_unref (offscreen);
+
+ cogl_texture_set_region (texture,
+ 0, 0,
+ (size - width) / 2, (size - height) / 2,
+ width, height,
+ width, height,
+ gdk_pixbuf_get_has_alpha (pixbuf) ? COGL_PIXEL_FORMAT_RGBA_8888 : COGL_PIXEL_FORMAT_RGB_888,
+ gdk_pixbuf_get_rowstride (pixbuf),
+ gdk_pixbuf_get_pixels (pixbuf));
+ return texture;
}
static cairo_surface_t *
if (pixbuf == NULL)
goto out;
- texdata = pixbuf_to_cogl_handle (pixbuf);
+ texdata = pixbuf_to_cogl_handle (pixbuf, data->enforced_square);
g_object_unref (pixbuf);
if (pixbuf != NULL)
{
- texdata = pixbuf_to_cogl_handle (pixbuf);
+ texdata = pixbuf_to_cogl_handle (pixbuf, FALSE);
g_object_unref (pixbuf);
clutter_texture_set_cogl_texture (bind->texture, texdata);
request->icon = g_object_ref (icon);
request->icon_info = info;
request->width = request->height = size;
+ request->enforced_square = TRUE;
load_icon_pixbuf_async (cache, icon, info, size, colors, NULL, on_pixbuf_loaded, request);
}
clutter_actor_set_size (CLUTTER_ACTOR (texture), width, height);
- texdata = pixbuf_to_cogl_handle (pixbuf);
+ texdata = pixbuf_to_cogl_handle (pixbuf, FALSE);
set_texture_cogl_texture (texture, texdata);
if (!pixbuf)
goto out;
- texdata = pixbuf_to_cogl_handle (pixbuf);
+ texdata = pixbuf_to_cogl_handle (pixbuf, FALSE);
g_object_unref (pixbuf);
if (policy == ST_TEXTURE_CACHE_POLICY_FOREVER)
return NULL;
}
- texdata = pixbuf_to_cogl_handle (pixbuf);
+ texdata = pixbuf_to_cogl_handle (pixbuf, TRUE);
g_object_unref (pixbuf);
set_texture_cogl_texture (texture, texdata);
data->thumbnail = TRUE;
data->width = size;
data->height = size;
+ data->enforced_square = TRUE;
data->textures = g_slist_prepend (data->textures, g_object_ref (texture));
load_thumbnail_async (cache, uri, mimetype, size, NULL, on_pixbuf_loaded, data);
}
data->recent_info = gtk_recent_info_ref (info);
data->width = size;
data->height = size;
+ data->enforced_square = TRUE;
data->textures = g_slist_prepend (data->textures, g_object_ref (texture));
load_recent_thumbnail_async (cache, info, size, NULL, on_pixbuf_loaded, data);
}